﻿function listenPlaylist(playlistId) {
	var data = {	'o' : 'getSongsId',
					'id' : playlistId};
	$.getJSON('app/playlist/ajaxPlaylist.php', data, function(recData) {
		if (recData.found == "true") {
			var songsIdVideo = new Array();
			for (i = 0; i < recData.songs.length; i++) {
				songsIdVideo[i] = recData.songs[i].idVideo;
			}
			player.loadPlayList(songsIdVideo);
		}
	});
}

function viewMyPlaylists() {
	var data = {'o' : 'view_my_playlists'};
	$.getJSON('app/playlist/ajaxPlaylist.php', data, function(recData) {
		$("#explorer_div").html(playlistsToHTML(recData.playlists, false));
	});
}

function viewMyFavorites() {
	var data = {'o' : 'view_my_favorites'};
	$.getJSON('app/playlist/ajaxPlaylist.php', data, function(recData) {
		$("#explorer_div").html(playlistsToHTML(recData.playlists, true));
	});
}

function viewPlaylist(playlistId) {
	var data = {	'o' : 'viewPlaylist',
					'id' : playlistId};
	$.getJSON('app/playlist/ajaxPlaylist.php', data, function(recData) {
		if (recData.found == "true") {
			$("#explorer_div").html(playlistToHTML(recData.playlist));
			showVotationButtons(recData.playlist.letVote, recData.playlist.id);
			if (recData.playlist.isFavorite == 'false')
				showFavoriteButton(recData.playlist.id);
		}
	});
}

function positiveVote(playlistId) {
	var data = {	'o' : 'positiveVote',
					'id' : playlistId};
	$.getJSON('app/playlist/ajaxPlaylist.php', data, function(recData) {
		if (recData.found == "true") {
			$("#positiveVotes_div").html("Positivos JS: " + recData.positiveVotes);
			showVotationButtons("false",-1);
		}
	});
}

function negativeVote(playlistId) {
	var data = {	'o' : 'negativeVote',
					'id' : playlistId};
	$.getJSON('app/playlist/ajaxPlaylist.php', data, function(recData) {
		if (recData.found == "true") {
			$("#negativeVotes_div").html("Negativos JS: " + recData.negativeVotes);
			showVotationButtons("false",-1);
		}
	});
}

function addFavorite(playlistId) {
	var data = {	'o' : 'addFavorite',
					'id' : playlistId};
	$.getJSON('app/playlist/ajaxPlaylist.php', data, function(recData) {
		if (recData.success == "true") {
			$("#favorite_button_div").html('')
		}
	});
}

function deleteFavorite(playlistId) {
	var data = {	'o' : 'deleteFavorite',
					'id' : playlistId};
	$.getJSON('app/playlist/ajaxPlaylist.php', data, function(recData) {
		if (recData.success == "true") {
			$("#tr_playlist_" + playlistId).remove()
		}
	});
}

function showEditPlaylistMenu(playlistId) {
	var data = {	'o' : 'viewPlaylist',
					'id' : playlistId};
	$.getJSON('app/playlist/ajaxPlaylist.php', data, function(recData) {
		showEditPlaylistDiv(recData.playlist);
	});
}

function createPlaylist(playlistName, playlistSongs) {
	var data = {	'o' : 'createPlaylist',
					'name' : playlistName,
					'songs[]' : playlistSongs};
	$.getJSON('app/playlist/ajaxPlaylist.php', data, function(recData) {
		$("#explorer_div").html(playlistsToHTML(recData.playlists, false));
	});
}

function editPlaylist(playlistId, playlistName, playlistSongs) {
	var data = {	'o' : 'editPlaylist',
					'id' : playlistId,
					'name' : playlistName,
					'songs[]' : playlistSongs};
	$.getJSON('app/playlist/ajaxPlaylist.php', data, function(recData) {
		$("#explorer_div").html(playlistsToHTML(recData.playlists, false));
	});
}

function deletePlaylist(playlistId) {
	var data = {	'o' : 'deletePlaylist',
					'id' : playlistId};
	$.getJSON('app/playlist/ajaxPlaylist.php', data, function(recData) {
		$("#explorer_div").html(playlistsToHTML(recData.playlists, false));
	});
}